<template>
  <div class="container">
    <div class="header">
      <el-button icon="el-icon-plus" @click="showAddDialog('caipin')">新增菜品分类</el-button>
      <el-button icon="el-icon-plus" @click="showAddDialog('taocan')">新增套餐分类</el-button>
      <AddDialog 
      :visible.sync="showDialogVisible"
      :type="dialogType"
      :currentRow="selectedRow" 
      @save-completed="init" 
    />
    </div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="name" label="分类名称"> </el-table-column>
      <el-table-column prop="type" label="分类类型">
        <template v-slot="{ row }">
          {{ row.type == "1" ? "菜品分类" : "套餐分类" }}
        </template>
      </el-table-column>
      <el-table-column prop="updateTime" label="操作时间">
         </el-table-column>
      <el-table-column prop="sort" label="排序"> </el-table-column>
      <el-table-column label="操作">
        <template v-slot="{ row }">
          <el-link type="primary" @click="showAddDialog('xiugai',row)">修改</el-link>
          <el-divider direction="vertical"></el-divider>
          <el-popconfirm
            title="确认调整该账号的状态?"
            @onConfirm="handleChangeStauts(row)"
          >
            <el-link type="danger" slot="reference">删除</el-link>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <div class="footer">
      <Pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageInfo.page"
          :page-size="pageInfo.pageSize"
          :total="total"
        />
    </div>
  </div>
</template> 
<script>
import { getFenlei } from "@/api/fenlei";
import AddDialog from '@/views/fenlei/components/AddDialog'
import Pagination from '@/components/Pagination/index.vue'
export default {
  components: {AddDialog,Pagination},//?
  data() {
    return {
      input: "",
      searchQuery: "",
      tableData: [],
      pageInfo: {
        page: 1,
        pageSize: 10,
      },
      total: 0,
      searchTimer: null,
      showDialogVisible: false,
      dialogType: 'caipin',
      selectedRow: null,
      form: {
        name: "",
        sort: "",
        type: "",
        id: "",
      },
      formLabelWidth: "120px",
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      getFenlei(this.pageInfo).then((res) => {
        const { records, total } = res.data;
        this.tableData = records;
        this.total = total;
      });
    },
    showAddDialog(type,row) {
      this.dialogType = type
      this.selectedRow = row
      this.showDialogVisible = true
    },  
    handleSearchInput() {
      clearTimeout(this.searchTimer);
      this.searchTimer = setTimeout(() => {
        this.pageInfo.page = 1; // 重置到第一页
        this.init();
      }, 300);
    },

    handleSizeChange(val) {
      this.pageInfo.page = 1;
      this.pageInfo.pageSize = val;
      this.init();
    },
    handleCurrentChange(val) {
      this.pageInfo.page = val;
      this.init();
    },
   
  },
};
</script>
  
  <style lang="scss" scoped>
.container {
  padding: 33px;
  .header {
    display: flex;
    justify-content: flex-start;
    .el-input {
      width: 250px;
    }
  }
  .el-table {
    margin-top: 20px;
  }
  .footer {
    margin-top: 20px;
    display: flex;
    justify-content: center;
  }
}
</style>